package com.kim.client.factory;


import com.kim.client.interfaces.MessageStrategy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Slf4j
@ApplicationScoped
public class StrategyBeanFactory {


    private final Map<String, MessageStrategy> processors = new ConcurrentHashMap<>();

    @Inject
    void init(Instance<MessageStrategy> processorInstances) {
        for (MessageStrategy processor : processorInstances) {
            String name = processor.getClass().getSimpleName();
            processors.put(name, processor);
        }
    }



    public MessageStrategy getProcessor(String processorType) {
        return processors.get(processorType);
    }
}